home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 May / SGI IRIX 6.5 Applications 1999 May.iso / dist / appletalk.idb / usr / etc / appletalk / ksd_restart.z / ksd_restart
Text File  |  1998-04-27  |  3KB  |  119 lines

  1. #!/bin/csh -f
  2. #
  3. #  @(#)ksd_restart    8.6  98/03/10     
  4. #
  5. # ksd_restart - halt/restart AppleShare
  6. # usage: ksd_retart [servername]
  7. #
  8. #
  9. set path=(/bin /etc /usr/{bin,ucb,bsd} /usr/etc .)
  10. set SERVICES=/usr/etc/appletalk/services
  11.  
  12. if (-x /bin/id) then
  13.     if (`/bin/id | grep -c uid=0` > 0) then
  14.         set me=root
  15.     else
  16.         set me=notroot
  17.     endif
  18. else
  19.     set me=`whoami`
  20. endif
  21. if ("$me" != root) then 
  22.     echo "You must have root privileges to run this script"
  23.     exit 1
  24. endif
  25.  
  26. if ("$1" == "") then
  27.     set pid=`grep AFPServer /usr/adm/appletalk/nbpreg_pids | tail -1 | awk '{print $1}'`
  28.     set name=`grep AFPServer /usr/adm/appletalk/nbpreg_pids | tail -1 | awk '{print $2}'`
  29. else 
  30.     set pid=`grep "$1" /usr/adm/appletalk/nbpreg_pids | grep AFPServer | tail -1 | awk '{print $ 1}'`
  31.     set name="$1"
  32. endif
  33.  
  34. if ("$pid" == "0" || "$pid" == "") then
  35.     if ("$1" == "") then
  36.         echo "I don't see a AppleShare server running on this machine"
  37.     else
  38.         echo "I don't see AppleShare server $1 running on this machine"
  39.     endif
  40.     goto restart
  41. endif
  42.  
  43. repprint:
  44. echo -n "Do you really want to halt the AppleShare daemon? "
  45. set resp=$<
  46. if ("$resp" =~ [Nn]*) then
  47.     echo "Leaving AppleShare running."
  48.     exit 1
  49. else if ("$resp" !~ [Yy]*) then
  50.     echo Please answer \"yes\" or \"no\":
  51.     goto repprint
  52. endif
  53. endif
  54.  
  55. echo -n "Do you want to give the users time to disconnect[y]? "
  56. set resp=$<
  57. if ("$resp" !~ [Nn]*) then
  58. mins:
  59.     echo -n "How many minutes do you want to wait[2]: " 
  60.     set mins=$<
  61.     if ($mins == "") then
  62.         set mins = "2"
  63.     endif
  64.     @ secs = $mins * 60
  65.     if ($mins != "0" && $secs == "0") then
  66.         echo "Invalid minutes $mins, try again."
  67.         goto mins
  68.     endif
  69.     
  70.     echo -n "Do you want customize the logout message[n]? "
  71.     set resp=$<
  72.     if ("$resp" =~ [Yy]*) then
  73.         echo "Enter the logout message now, followed by a ^D"    
  74.         cat > /tmp/ksmessage.$$
  75.     else
  76.         echo "AppleShare being shut down" > /tmp/ksmessage.$$
  77.     endif
  78.     while ($mins != "0")
  79.         rm -f /usr/adm/appletalk/msg
  80.         echo "    $mins" > /usr/adm/appletalk/msg
  81.         cat /tmp/ksmessage.$$ >>  /usr/adm/appletalk/msg
  82.         chmod 644 /usr/adm/appletalk/msg
  83.         kill -USR2 $pid
  84.                 echo "Server will shut down in $mins minute(s)"
  85.                 @ mins--
  86.         sleep 60
  87.         end
  88.     rm -f /usr/adm/appletalk/msg
  89.     rm -f /tmp/ksmessage.$$
  90. endif
  91.  
  92. echo "Killing the daemon..."
  93. set res=`kill $pid`
  94. if ($status) then
  95.     echo "Error killing daemon: $res"
  96.     echo "Attempting to remove registered name"
  97.     /usr/etc/appletalk/nbpremove -T AFPServer -O $name 
  98. endif
  99.  
  100. sleep 5
  101. set newpid=`grep AFPServer /usr/adm/appletalk/nbpreg_pids | tail -1 | awk '{print $1}'`
  102.  
  103. if ("$newpid" == "$pid") then 
  104.     echo "ERROR: The daemon did not die."
  105.     exit 1
  106. endif
  107.  
  108. restart:
  109.  
  110. set noglob
  111. set line=`grep ksd ${SERVICES} | tail -1`
  112.  
  113. echo -n "Do you want to re-start the AppleShare daemon[y]? "
  114. set resp=$<
  115. if ("$resp" !~ [nN]*) then
  116.     echo "Restarting AppleShare $line"
  117.     echo $line | csh -fe
  118. endif
  119.